/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AdminCenterMain;

import CommonValue.CityName;
import SocketBusiness.BossOrderSlave;
import CommonValue.CommonString;
import CommonValue.NetConfig;
import CommonValue.Pressure;
import CommonValue.SystemSign;
import CommonValue.Temperature;
import CommonValue.Wind;
import DTO.ControlDTO;
import DTO.PacketDTO;
import UI.ViewCurrentWeatherScreen1;
import UI.WeatherStationScreen;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class AdminCenterMain {

    private static final String systemName = SystemSign.AdminCenter;

    public static void main(String[] args) {
        System.out.println(systemName + CommonString.MainProgram);

        PacketDTO _hourlyReport = new PacketDTO(SystemSign.AdminCenter);
        PacketDTO _trigger = new PacketDTO(SystemSign.AdminCenter);
        ControlDTO _operationAC = new ControlDTO(systemName, systemName); // tu no dieu khien chinh no
        ControlDTO _operationWS = new ControlDTO(systemName, SystemSign.WeatherSystem);// bien dieu khien on/off Weather System
        ControlDTO _operationAS = new ControlDTO(systemName, SystemSign.AlarmSystem);//bien dieu khien on/off Alarm System

        ReceiveReportFromWS AC_listen_WS = new ReceiveReportFromWS(SystemSign.AdminCenter, NetConfig.AdmCen_Listen_WeaSys_Port,_operationAC, _hourlyReport);
        Thread t1 = new Thread(AC_listen_WS, systemName + CommonString.ThreadName + 1);
        t1.start();

        ReceiveTriggerFromAS AC_listen_AS = new ReceiveTriggerFromAS(SystemSign.AdminCenter, NetConfig.AdmCen_Listen_AlaSys_Port,_operationAC, _trigger);
        Thread t2 = new Thread(AC_listen_AS, systemName + CommonString.ThreadName + 2);
        t2.start();

        // CODE MAU LAY DU LIEU DE VE

        // ham ve        
//        DrawThread dt = new DrawThread(_hourlyReport);
//        Thread t3 = new Thread(dt,"Draw");
//        t3.start();

        List<String> li = new ArrayList<String>();
        li.add(Temperature.SIGN);
        li.add(Wind.SIGN);
        li.add(Pressure.SIGN);
        new ViewCurrentWeatherScreen1(CityName.HANOI, li, _hourlyReport).setVisible(true);

        
        BossOrderSlave controlWS = new BossOrderSlave(systemName, NetConfig.WeatherSystemIP, NetConfig.AdmCen_Control_WeaSys_Port,_operationAC ,_operationWS);
        Thread t4 = new Thread(controlWS, systemName + CommonString.ThreadName + 4);
        t4.start();

        BossOrderSlave controlAS = new BossOrderSlave(systemName, NetConfig.AlarmSystemIP, NetConfig.AdmCen_Control_AlaSys_Port,_operationAC, _operationAS);
        Thread t5 = new Thread(controlAS, systemName + CommonString.ThreadName + 5);
        t5.start();

//        new MainScreen(_hourlyReport, _operationWS, _operationAS).setVisible(true);

        new WeatherStationScreen("admin", _operationWS, _operationAS).setVisible(true);
        //_operationWS.setFlag(false);


//        for (;;) {// test control he thong
//            System.out.println("DA THAY DOI FLAG");
//            synchronized (_operationAS) {
//                _operationAS.setFlag(!_operationAS.getFlag());
//                System.out.println("_operationAS" + _operationAS.getFlag());
//            }
//            synchronized (_operationWS) {
//                _operationWS.setFlag(!_operationWS.getFlag());
//                System.out.println("_operationWS" + _operationWS.getFlag());
//            }
//            
//            try {
//                Thread.sleep(20000);
//            } catch (InterruptedException ex) {
//                Logger.getLogger(AdminCenterMain.class.getName()).log(Level.SEVERE, null, ex);
//            }
//        }

        
    }
}
